﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>订单列表</title>
<link rel="icon" href="favicon.ico" type="image/ico">


<meta name="author" content="yinqi">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/materialdesignicons.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
</head>

<body data-logobg="color_8" data-sidebarbg="color_8">
<div class="layout-web">
  <div class="layout-container">
    <jsp:include page="nav.jsp"></jsp:include>
    <!--页面主要内容-->
    <main class="layout-content">

      <div class="container-fluid">

        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-toolbar clearfix">
                <form class="pull-right search-bar" method="get" action="orderlist.action" role="form">
                  <div class="input-group">
                    <div class="input-group-btn">
                      <input type="hidden" name="search_field" id="search-field" value="${search_field}">
                      <button class="btn btn-default dropdown-toggle" id="search-btn" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">
                      <c:if test="${search_field=='gname'}">
                        商品名称 <span class="caret"></span>
                      </c:if>
                      <c:if test="${search_field=='eid'}">
                        操作员工 <span class="caret"></span>
                      </c:if>
                      <c:if test="${search_field=='state'}">
                        订单状态 <span class="caret"></span>
                      </c:if>
                      <c:if test="${search_field!='state'&&search_field!='eid'&&search_field!='gname'}">
                        商品名称 <span class="caret"></span>
                      </c:if>
                      </button>
                      <ul class="dropdown-menu">
                        <li> <a tabindex="-1" onclick="fun1()" data-field="gname">商品名称</a> </li>
                        <li> <a tabindex="-1" onclick="fun2()" data-field="eid">操作员工</a> </li>
                        <li> <a tabindex="-1" onclick="fun3()" data-field="state">订单状态</a> </li>
                      </ul>
                    </div>
                    <input type="text" class="form-control" value="${content}" name="keyword" placeholder="请输入名称">
                  </div>
                </form>
                <div class="toolbar-btn-action">
                  <c:if test="${role.rid==11||role.rid==7}">
                    <button class="btn btn-primary m-r-5" onclick="batchPurchase()"><i class="mdi mdi-plus"></i> 一键采购</button>
                  </c:if>
                </div>
              </div>
              <div class="card-body">

                <div class="table-responsive">
                  <table class="table table-bordered">
                    <thead>
                      <tr>
                        <th>
                          <label class="checkbox checkbox-primary">

                          </label>
                        </th>
                        <th>订单编号</th>
                        <th>操作员工</th>
                        <th>订单状态</th>
                        <th>生成时间</th>
                        <th>商品名称</th>
                        <th>数量</th>
                        <th>金额</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                    <tbody>
                    <c:forEach var="order" items="${orders}">
                        <tr>
                          <td>
                            <label class="checkbox checkbox-primary">
                              <input type="checkbox" name="sids" value="${order.sid},${order.oid}"><span></span>
                            </label>
                          </td>
                          <td>${order.oid}</td>
                          <c:forEach var="emp" items="${emps}">
                            <c:if test="${emp.eid==order.eid}">
                              <td>${emp.ename}</td>
                            </c:if>
                          </c:forEach>
                          <c:forEach var="st" items="${states}">
                            <c:if test="${st.sid==order.sid}">
                              <c:if test="${order.sid==1}">
                                <td style="color: deeppink;font-weight: bold;font-size: 18px">${st.state}</td>
                              </c:if>
                              <c:if test="${order.sid==2}">
                                <td style="color: #0FB25F;font-weight: bold;font-size: 18px">${st.state}</td>
                              </c:if>
                              <c:if test="${order.sid!=1&&order.sid!=2}">
                                <td>${st.state}</td>
                              </c:if>
                            </c:if>
                          </c:forEach>
                          <td>${order.buytime}</td>
                          <c:forEach var="cmt" items="${commodities}">
                            <c:if test="${cmt.gid==order.gid}">
                              <td>${cmt.gname}</td>
                            </c:if>
                          </c:forEach>
                          <td>${order.count}</td>
                          <c:forEach var="cmt" items="${commodities}">
                            <c:if test="${cmt.gid==order.gid}">
                              <td style="font-weight: bold">${(order.count)*(cmt.price)}</td>
                            </c:if>
                          </c:forEach>

                          <td>
                            <div class="btn-group">
                              <c:if test="${order.sid==1}">
                                <c:if test="${role.rid==11||role.rid==7}">
                                  <a class="btn btn-warning" href="orderedit.action?type=1&oid=${order.oid}"></i>修改订单</a>
                                  <a class="btn btn-cyan" href="orederstateedit.action?type=cancel&oid=${order.oid}">取消订单</a>
                                </c:if>
                              </c:if>
                              <c:if test="${order.sid==2}">
                                <c:if test="${role.rid==11||role.rid==7}">
                                  <a class="btn btn-success m-r-5" href="orederstateedit.action?type=purchase&oid=${order.oid}"></i>立即采购</a>
                                </c:if>
                              </c:if>
                            </div>
                          </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                  </table>
                </div>

              <center>
                <ul class="pagination">
                  <%-- <li class="disabled"><span>«</span></li>--%>
                  <li class="active"><span>第${pageUtil.currentPage}页</span></li>
                  <li><a href="orderlist.action?cp=1&search_field=${search_field}&keyword=${content}">首页</a></li>
                  <li><a href="orderlist.action?cp=${pageUtil.currentPage-1}&search_field=${search_field}&keyword=${content}">上一页</a></li>
                  <li><a href="orderlist.action?cp=${pageUtil.currentPage+1}&search_field=${search_field}&keyword=${content}">下一页</a></li>
                  <li><a href="orderlist.action?cp=${pageUtil.totalPage}&search_field=${search_field}&keyword=${content}">尾页</a></li>
                    <li class="active"><span>共${pageUtil.totalPage}页</span></li>
                </ul>
              </center>

              </div>
            </div>
          </div>

        </div>

      </div>

    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript">
$(function(){
    $('.search-bar .dropdown-menu a').click(function() {
        var field = $(this).data('field') || '';
        $('#search-field').val(field);
        $('#search-btn').html($(this).text() + ' <span class="caret"></span>');
    });
});
</script>
<script type="text/javascript">
  function batchPurchase(){
      var oids = "";
      var  sidItems = document.getElementsByName("sids");
      for (var i=0;i<sidItems.length;i++){
        //将状态id和订单id拆分
        var val = sidItems[i].value.split(",");
        if (val[0]==2){
          sidItems[i].checked=true;
          //将订单编号拼接
          oids+=val[1]+",";
        }
      }
      //删除最后一个","
    oids = oids.substring(0,oids.lastIndexOf(","));
    //跳转到控制器
    location.href="orederstateedit.action?type=batchpurchase&oids="+oids;
  }

  function fun1(){
    document.getElementById('search-field').value='gname';
  }

  function fun2(){
    document.getElementById('search-field').value='eid';
  }
  function fun3(){
    document.getElementById('search-field').value='state';
  }
</script>
</body>
</html>